package com.foruo.demo.elasticjob;

import com.dangdang.ddframe.job.executor.handler.JobExceptionHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;


@Component
public class MyElasticJobExceptionHandler implements JobExceptionHandler {

    Logger logger = LoggerFactory.getLogger(MyElasticJobExceptionHandler.class);

    @Override
    public void handleException(String jobName, Throwable cause) {
        try{
            Class.forName("com.mysql.jdbc.Driver");
            Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/javademo?user=root&password=root&useUnicode=true&characterEncoding=UTF8");

            PreparedStatement ps = connection.prepareStatement("select * from demo");
            ps.execute();
            connection.commit();
            connection.close();
        }catch (Exception e){

        }


        logger.error("MyElasticJobExceptionHandler happened");
    }
}
